package com.von.handler;

import cn.hutool.core.util.StrUtil;
import com.von.exceptions.OperationRuntimeException;
import com.von.result.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author xiaosai
 * @version 1.0
 * @date 2021/6/21 16:23
 * @describe
 * @className
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public R handleException(Exception e){
        e.printStackTrace();
        String msg = e.getMessage();
        if(StrUtil.isEmpty(msg)){
            msg = "系统繁忙，稍后重试！";
        }
        return R.failed(msg);
    }
    @ResponseBody
    @ExceptionHandler(OperationRuntimeException.class)
    public R handleException(OperationRuntimeException e){
        e.printStackTrace();
        String msg = e.getMessage();
        if(StrUtil.isEmpty(msg)){
            msg = "系统繁忙，稍后重试！";
        }
        return R.failed(msg);
    }
}
